package com.starhub.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.starhub.web.model.ProductCarousel;
import com.starhub.web.model.Tile;


@Controller
public class AdminController extends StarHubBaseController {

	@RequestMapping(value = "/editTile.html")
	public ModelAndView editTile(@RequestParam(value = "tileId") Integer tileId, ModelMap model) {
		Tile tile = tileHost.getTileDetails(tileId);
		model.addAttribute("tile", tile);
		return new ModelAndView("common/editTile", model);
	}
	
	@RequestMapping(value = "/submitEditTile.html", method = RequestMethod.POST)
	public ModelAndView submitEditTile(@ModelAttribute(value = "tile") Tile tile, ModelMap model) {
		tileHost.updateTile(tile);
		return new ModelAndView("common/editTile", model);
	}
	
	@RequestMapping(value = "/editProductCarousel.html")
	public ModelAndView editProductCarousel(@RequestParam(value = "productId") Integer productId, ModelMap model) {
		ProductCarousel productCarousel = productHost.getProducCarouselDetails(productId);
		model.addAttribute("productCarousel", productCarousel);
		return new ModelAndView("common/editProductCarousel", model);
	}
	
	@RequestMapping(value = "/submitEditProductCarousel.html", method = RequestMethod.POST)
	public ModelAndView submitEditProductCarousel(@ModelAttribute(value = "productCarousel") ProductCarousel productCarousel, ModelMap model) {
		productHost.updateProductCarousel(productCarousel);
		return new ModelAndView("common/editProductCarousel", model);
	}
}
